package com.example.graduationdesignbackend.res;

import com.example.graduationdesignbackend.constants.ResponseCode;
import com.example.graduationdesignbackend.constants.UserCode;
import lombok.Data;

import java.io.Serializable;
@Data
public class Res<T> implements Serializable {
  private Integer code;

  private String message;

  private T result;

  private Res(T result, Integer code, String msg) {
    this.result = result;
    this.code = code;
    this.message = msg;
  }
  private Res(T result, ResponseCode resultCode) {
    this.result = result;
    this.code = resultCode.getCode();
    this.message = resultCode.getName();
  }
  private Res(T result, UserCode userCode) {
    this.result = result;
    this.code = userCode.getCode();
    this.message = userCode.getName();
  }

  public static Res<String> yuze(){
    return new Res<>("", ResponseCode.Success);
  }
  public static <T> Res<T> yuze(T data){
    return new Res<>(data, ResponseCode.Success);
  }
  public static Res<String> fail(ResponseCode resultCode){
    return new Res<>("",resultCode);
  }
  public static Res<String> fail(ResponseCode resultCode, String msg) {
    return new Res<>("", resultCode.getCode(), msg);
  }
  public static Res<String> fail(UserCode authCode) {
    return new Res<>("", authCode);
  }

  public static Res<String> fail(UserCode authCode,String msg) {
    return new Res<>("", authCode.getCode(),msg);
  }
}
